function [x]=filterLFP(x,SampRate,lowFreq,highFreq,remove60)
% function [x]=filterLFP(x,SampRate,lowFreq,highFreq)
% Performs a bandpass filter and a 60hz notch filter
% x is number of regions by number of time samples
% SampRate is the sampling rate, default=500
% lowFreq is the lower part of the bandpass filter, default=3
% highFreq is the higher part of the bandpass filter, default=60
%%
if nargin<2;SampRate=500;end
if nargin<3;lowFreq=3;end
if nargin<4;highFreq=60;end
if nargin<5;remove60=true;end
[nR,N]=size(x);
%% 60 Hz Notch Filter
if remove60
    filtfreq=60/SampRate*2; % Filter out 60Hz Signal
    filtbw=filtfreq/60; % 1Hz Bandwidth
    [filtb,filta]=iirnotch(filtfreq,filtbw);
end

%% Bandpass Filter
lowpass=lowFreq*2/SampRate;highpass=highFreq*2/SampRate;
[butterb,buttera]=butter(2,[lowpass,highpass]);

%% Perform Filters:
for r=1:nR
    if remove60;
        x(r,:)=filtfilt(filtb,filta,x(r,:));
    end
    x(r,:)=filtfilt(butterb,buttera,x(r,:));
    x(r,:)=x(r,:)-mean(x(r,:));
    x(r,:)=x(r,:)./std(x(r,:));
end